package com.letv.core.bean;

import com.letv.core.utils.MD5;

public class TimestampBean implements LetvBaseBean {
    private static final long serialVersionUID = 1L;
    /**
     * 服务器时间与本地时间的偏移
     * */
    private int offset;

    private static final TimestampBean tm = new TimestampBean();

    private TimestampBean() {
    }

    /**
     * 得到时间戳对象
     * */
    public static TimestampBean getTm() {
        return tm;
    }

    /**
     * 更新时间戳
     * */
    public void updateTimestamp(int newTimestamp) {
        long cur = System.currentTimeMillis();
        offset = (int) (cur / 1000 - newTimestamp);
        /**
         * 同时更新下载包的时间戳
         * */
        // com.letv.android.client.loader.db.TimestampBean.getTm().updateTimestamp(newTimestamp);
    }

    /**
     * 得到当前的服务器时间，由偏移量换算得来
     * */
    public int getCurServerTime() {
        long cur = System.currentTimeMillis();
        return (int) (cur / 1000 - offset);
    }
    
    /**
     * 生存videofile接口的key
     * */
    public static String generateVideoFileKey(String mid, String tm) {
        StringBuilder builder = new StringBuilder();
        builder.append(mid);
        builder.append(",");
        builder.append(tm);
        builder.append(",");
        builder.append("bh65OzqYYYmHRQ");

        return MD5.toMd5(builder.toString());
    }
}
